<!DOCTYPE html><html lang="zh-Hans" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>DreamcatcherDENG 的个人博客</title><meta name="author" content="dreamcatcherdeng"><meta name="copyright" content="dreamcatcherdeng"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="referrer" content="no-referrer"><meta property="og:type" content="website">
<meta property="og:title" content="DreamcatcherDENG 的个人博客">
<meta property="og:url" content="https://dreamcatcherdeng.github.io/personal-blog/page/3/index.html">
<meta property="og:site_name" content="DreamcatcherDENG 的个人博客">
<meta property="og:locale">
<meta property="og:image" content="https://n.sinaimg.cn/sinakd10100/452/w1080h972/20200416/93dc-iskepxs3894040.jpg">
<meta property="article:author" content="dreamcatcherdeng">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://n.sinaimg.cn/sinakd10100/452/w1080h972/20200416/93dc-iskepxs3894040.jpg"><link rel="shortcut icon" href="/personal-blog/img/favicon.png"><link rel="canonical" href="https://dreamcatcherdeng.github.io/personal-blog/page/3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/personal-blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/personal-blog/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"We didn't find any results for the search: ${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'DreamcatcherDENG 的个人博客',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-07-17 00:42:18'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/personal-blog/atom.xml" title="DreamcatcherDENG 的个人博客" type="application/atom+xml">
</head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://n.sinaimg.cn/sinakd10100/452/w1080h972/20200416/93dc-iskepxs3894040.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/personal-blog/archives/"><div class="headline">Articles</div><div class="length-num">34</div></a></div><div class="data-item"><a href="/personal-blog/tags/"><div class="headline">Tags</div><div class="length-num">0</div></a></div><div class="data-item"><a href="/personal-blog/categories/"><div class="headline">Categories</div><div class="length-num">35</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/personal-blog/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/personal-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/personal-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="/personal-blog/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-72rd8e.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/personal-blog/">DreamcatcherDENG 的个人博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> Search</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/personal-blog/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/personal-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/personal-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="/personal-blog/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">DreamcatcherDENG 的个人博客</h1><div id="site_social_icons"><a class="social-icon" href="https://github.com/DreamcatcherDENG" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/personal-blog/2022/07/13/GridLayout/" title="GridLayout"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-e7ek7k.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="GridLayout"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/GridLayout/" title="GridLayout">GridLayout</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.888Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/">Android 布局</a></span></div><div class="content">
1.GridLayout属性
2.GridLayout布局


GridLayout属性GridLayout的属性



属性
说明




orientation
设置排列方向


columnCount
设置列数，超过的部分换行显示


rowCount
设置行数，超过的部分换列显示




子控件的属性



属性
说明




layout_column
显示在第几列


layout_row
显示在第几行


layout_rowSpan
横向跨几行


layout_columnSpan
横向跨几列


layout_columnWeight
横向剩余空间的权重


layout_gravity
在网格中的显示位置


layout_rowWeight
纵向剩余空间的权重




GridLayout布局设置纵向排列，排列3行12345678910111213141516171819202122232425262728293031323334353637383940414243444546&lt;?xml version=&quot;1.0&quot; encoding= ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/personal-blog/2022/07/13/FrameLayout/" title="FrameLayout"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-e7ek7k.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="FrameLayout"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/FrameLayout/" title="FrameLayout">FrameLayout</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.886Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/">Android 布局</a></span></div><div class="content">
1.FrameLayout布局
2.FrameLayout前景色设置


FrameLayout布局123456789101112131415161718192021222324&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;    xmlns:tools=&quot;http://schemas.android.com/tools&quot;    android:layout_width=&quot;match_parent&quot;    android:layout_height=&quot;match_parent&quot;    android:background=&quot;#FF0000&q ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/personal-blog/2022/07/13/Fragment/" title="Fragment"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/romance-2258599_960_720.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="Fragment"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/Fragment/" title="Fragment">Fragment</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.885Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E6%8E%A7%E4%BB%B6/">Android 控件</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E6%95%88%E6%9E%9C/">效果</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E6%95%88%E6%9E%9C/Navigation%E7%BF%BB%E9%A1%B5/">Navigation翻页</a></span></div><div class="content">

在Activity中使用单个Fragment
在Activity中使用多个Fragment
动态添加Fragment
Activity与Fragment通信
Fragment生命周期
使用Fragment和ViewPager2实现navigation翻页效果



在Activity中使用单个Fragment创建一个空的Fragment
修改fragment_blank.xml123456789101112131415161718192021222324&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;    xmlns:tools=&quot;http://schemas.android.com/tools& ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/personal-blog/2022/07/13/FormatConvert/" title="Ffmpeg格式转换工具"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/samurai-2258604_960_720.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="Ffmpeg格式转换工具"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/FormatConvert/" title="Ffmpeg格式转换工具">Ffmpeg格式转换工具</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.881Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/%E8%87%AA%E7%BC%96%E5%B7%A5%E5%85%B7/">自编工具</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E8%87%AA%E7%BC%96%E5%B7%A5%E5%85%B7/%E8%84%9A%E6%9C%AC%E5%88%B6%E4%BD%9C/">脚本制作</a></span></div><div class="content">

官网下载ffmpeg工具

解压并将ffmpeg.exe存在的***\ffmpeg\bin目录添加到环境变量

在***\ffmpeg\bin目录下创建convert.bat文件
1ffmpeg -i %1 &quot;%~n1&quot;%2
若想转换后删除原视频，可添加bat命令
1del %1

在***\ffmpeg\bin目录下创建register.reg文件

需要把*替换成自己的文件路径

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\*\shell\Format_Convert]&quot;icon&quot;=&quot;***\\ffmpeg\\bin\\convert.ico&quot;&quot;SubCommands&quot;=&quot;toGIF;toPNG;toJPEG;toICO;toFL ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/personal-blog/2022/07/13/EditText/" title="EditText"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-0qxx54.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="EditText"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/EditText/" title="EditText">EditText</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.879Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E6%8E%A7%E4%BB%B6/">Android 控件</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/">常见问题</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%B7%B2%E8%A7%A3%E5%86%B3/">已解决</a></span></div><div class="content">
1.EditText常用属性
2.获取EditText中的内容
3.常见问题


EditText常用属性



属性
描述




hint
输入提示


textColorHint
输入提示的颜色


inputType
输入类型(具体可以输入哪些类型可以Ctrl+B查看)


drawableLeft[Right,Bottom,Top]
在输入框的左方添加可绘制资源


drawablePadding
设置可绘制资源与输入内容的间距


paddingLeft[Right,Bottom,Top]
设置内容(包括可绘制资源文件)与边框左边的间距




获取EditText中的内容1234567891011121314151617181920&lt;EditText    android:id=&quot;@+id/edit_one&quot;    android:layout_width=&quot;300dp&quot;    android:layout_height=&quot;100dp&quot;    android:drawableStart=&quot;@dr ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/personal-blog/2022/07/13/CustomView/" title="自定义View"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-e7ek7k.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="自定义View"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/CustomView/" title="自定义View">自定义View</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.877Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/">常见问题</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E6%95%88%E6%9E%9C/">效果</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%B7%B2%E8%A7%A3%E5%86%B3/">已解决</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android%EF%BC%8CAndroid-%E6%8E%A7%E4%BB%B6/">Android，Android 控件</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E6%95%88%E6%9E%9C/%E8%BF%9B%E5%BA%A6%E6%9D%A1%E5%8A%A0%E8%BD%BD%E6%95%88%E6%9E%9C/">进度条加载效果</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%B7%B2%E8%A7%A3%E5%86%B3/invalidate%E4%B8%8D%E7%94%9F%E6%95%88/">invalidate不生效</a></span></div><div class="content">

View创建的流程
自定义View
自定义属性
滑动解锁Demo
进度条加载效果



View的创建流程
自定义View要自定义View必须要继承View类，如果想要在xml 中使用就必须实现View(Context context, @Nullable AttributeSet attrs)构成方法。




方法
说明




onMeasure()
绘制前测量试图所占大小


onSizeChanged()
当视图大小发生改变时应该做的事


onDraw()
绘制的主体方法


dispathDraw()
将视图分发给父容器托管


onDrawForearound()
绘制前景




当View被创建时，会按照上述方法从上往下执行，onMeasure()会执行两次,主要的绘制方法为`onDraw(Canvas canvas)




方法
说明




canvas.drawCircle();
绘制一个圆


canvas.drawLine();
绘制一条线


canvas.drawRect();
绘制长方形


canvas.drawArc();
绘制圆弧


c ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/personal-blog/2022/07/13/ConstrainLayout/" title="ConstrainLayout"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/jungle_fantasy_deer_butterflies_night_trees_102121_1280x720.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="ConstrainLayout"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/ConstrainLayout/" title="ConstrainLayout">ConstrainLayout</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.870Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/">Android 布局</a></span></div><div class="content">
视频
ConstrainLayout直接使用布局设计器拖动更方便，无需记属性
</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/personal-blog/2022/07/13/Button/" title="Button"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-0qxx54.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="Button"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/Button/" title="Button">Button</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.869Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E6%8E%A7%E4%BB%B6/">Android 控件</a></span></div><div class="content">
1.点击Button切换Button背景
2.Button点击事件


点击Button切换Button背景
xml方式

在drawable资源文件夹中创建两个可绘制矢量图







在drawable资源文件夹下创建一个选择器btn_selector.xml
state_pressed表示点击时的显示的图片，另一个为默认图片
12345&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;    &lt;item android:state_pressed=&quot;true&quot; android:drawable=&quot;@drawable/ic_baseline_access_time_24&quot;/&gt;    &lt;item android:drawable=&quot;@drawable/ic_baseli ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/personal-blog/2022/07/13/BottomNavigationView/" title="BottomNavigationView"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-e7ek7k.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="BottomNavigationView"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/BottomNavigationView/" title="BottomNavigationView">BottomNavigationView</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.866Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Android-%E6%8E%A7%E4%BB%B6/">Android 控件</a></span></div><div class="content">
1.BottomNavigationView


BottomNavigationView在activity_main.xml中使用BottomNavigationView
123456789&lt;com.google.android.material.bottomnavigation.BottomNavigationView        android:id=&quot;@+id/bottom_nav_view&quot;        android:layout_width=&quot;match_parent&quot;        android:layout_height=&quot;wrap_content&quot;        app:itemTextAppearanceActive=&quot;@style/bottom_tab_title_active&quot;        app:itemTextAppearanceInactive=&quot;@style/bottom_tab_title_inactive&quot;        app:la ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/personal-blog/2022/07/13/Binding/" title="View Binding and Data Binding"><img class="post_bg" src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/jungle_fantasy_deer_butterflies_night_trees_102121_1280x720.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="View Binding and Data Binding"></a></div><div class="recent-post-info"><a class="article-title" href="/personal-blog/2022/07/13/Binding/" title="View Binding and Data Binding">View Binding and Data Binding</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">Created</span><time datetime="2022-07-13T09:38:00.862Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/">Android</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/Android/Jetpack/">Jetpack</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E6%95%88%E6%9E%9C/">效果</a><i class="fas fa-angle-right article-meta-link"></i><a class="article-meta__categories" href="/personal-blog/categories/%E6%95%88%E6%9E%9C/%E6%9C%AC%E5%9C%B0%E5%8F%8A%E7%BD%91%E7%BB%9C%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD/">本地及网络图片加载</a></span></div><div class="content">

View Binding的使用
Data Binding的使用



View Binding的使用需要在使用View Binding的模块中开启该功能
123456android &#123;        ...        viewBinding &#123;            enabled = true        &#125;    &#125;
在Activity中使用1234567891011121314151617181920&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;    xmlns:tools=&qu ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/personal-blog/page/2/#content-inner"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/personal-blog/">1</a><a class="page-number" href="/personal-blog/page/2/#content-inner">2</a><span class="page-number current">3</span><a class="page-number" href="/personal-blog/page/4/#content-inner">4</a><a class="extend next" rel="next" href="/personal-blog/page/4/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://n.sinaimg.cn/sinakd10100/452/w1080h972/20200416/93dc-iskepxs3894040.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">dreamcatcherdeng</div><div class="author-info__description"></div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/personal-blog/archives/"><div class="headline">Articles</div><div class="length-num">34</div></a></div><div class="card-info-data-item"><a href="/personal-blog/tags/"><div class="headline">Tags</div><div class="length-num">0</div></a></div><div class="card-info-data-item"><a href="/personal-blog/categories/"><div class="headline">Categories</div><div class="length-num">35</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/DreamcatcherDENG" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/personal-blog/2022/07/13/RegularExpression/" title="正则表达式"><img src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/romance-2258599_960_720.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="正则表达式"/></a><div class="content"><a class="title" href="/personal-blog/2022/07/13/RegularExpression/" title="正则表达式">正则表达式</a><time datetime="2022-07-13T09:38:01.002Z" title="Created 2022-07-13 17:38:01">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/personal-blog/2022/07/13/Nodejs/" title="JavaScript and NodeJs"><img src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-0qxx54.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="JavaScript and NodeJs"/></a><div class="content"><a class="title" href="/personal-blog/2022/07/13/Nodejs/" title="JavaScript and NodeJs">JavaScript and NodeJs</a><time datetime="2022-07-13T09:38:00.960Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/personal-blog/2022/07/13/MySQL/" title="MySQL"><img src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-e7ek7k.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="MySQL"/></a><div class="content"><a class="title" href="/personal-blog/2022/07/13/MySQL/" title="MySQL">MySQL</a><time datetime="2022-07-13T09:38:00.957Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/personal-blog/2022/07/13/JAVA/" title="JAVA"><img src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-72rd8e.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="JAVA"/></a><div class="content"><a class="title" href="/personal-blog/2022/07/13/JAVA/" title="JAVA">JAVA</a><time datetime="2022-07-13T09:38:00.948Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/personal-blog/2022/07/13/ViewPager/" title="ViewPager"><img src="https://gitee.com/DreamcatcherDENG/drawing-bed/raw/master/img/wallhaven-0qxx54.jpg" onerror="this.onerror=null;this.src='/personal-blog/img/404.jpg'" alt="ViewPager"/></a><div class="content"><a class="title" href="/personal-blog/2022/07/13/ViewPager/" title="ViewPager">ViewPager</a><time datetime="2022-07-13T09:38:00.929Z" title="Created 2022-07-13 17:38:00">2022-07-13</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>Categories</span>
            <a class="card-more-btn" href="/personal-blog/categories/" title="More">
    <i class="fas fa-angle-right"></i></a>
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/"><span class="card-category-list-name">Android</span><span class="card-category-list-count">26</span></a><ul class="card-category-list child"><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E5%8A%A8%E7%94%BB/"><span class="card-category-list-name">Android 动画</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/"><span class="card-category-list-name">Android 布局</span><span class="card-category-list-count">6</span></a><ul class="card-category-list child"><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/layout-weight/"><span class="card-category-list-name">layout_weight</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/margin/"><span class="card-category-list-name">margin</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E5%B8%83%E5%B1%80/padding/"><span class="card-category-list-name">padding</span><span class="card-category-list-count">1</span></a></li></ul></li><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E6%8E%A7%E4%BB%B6/"><span class="card-category-list-name">Android 控件</span><span class="card-category-list-count">12</span></a><ul class="card-category-list child"><li class="card-category-list-item "><a class="card-category-list-link" href="/personal-blog/categories/Android/Android-%E6%8E%A7%E4%BB%B6/%E5%9B%BE%E7%89%87%E6%8B%89%E4%BC%B8%E5%8F%8A%E5%A1%AB%E5%85%85/"><span class="card-category-list-name">图片拉伸及填充</span><span class="card-category-list-count">1</span></a></li></ul></li></ul></li>
            </ul></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>Archives</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/personal-blog/archives/2022/07/"><span class="card-archive-list-date">July 2022</span><span class="card-archive-list-count">34</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>Info</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">Article :</div><div class="item-count">34</div></div><div class="webinfo-item"><div class="item-name">Total Count :</div><div class="item-count">54.9k</div></div><div class="webinfo-item"><div class="item-name">UV :</div><div class="item-count" id="busuanzi_value_site_uv"></div></div><div class="webinfo-item"><div class="item-name">PV :</div><div class="item-count" id="busuanzi_value_site_pv"></div></div><div class="webinfo-item"><div class="item-name">Last Push :</div><div class="item-count" id="last-push-date" data-lastPushDate="2022-07-16T16:42:17.888Z"></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By dreamcatcherdeng</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">Local search</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  Loading the Database</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="Search for Posts" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/personal-blog/js/utils.js"></script><script src="/personal-blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="/personal-blog/js/search/local-search.js"></script><div class="js-pjax"></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/personal-blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/personal-blog/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":250,"height":300,"hOffset":0,"vOffset":0,"opacity":0.1},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>